#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>
typedef struct book {
    char name[100];
    int price;
}book;
int main()
{
    int n;
    scanf("%d", &n);
    book book[100];
    for (int i = 0; i < n; i++)
    {
        scanf("%s%*C%d", &(book[i].name), &(book[i].price));
    }
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < n - i; j++)
        {
            if (book[j].price > book[j + 1].price)
            {
                char a[100] = "\0";
                strcpy(a, book[j].name);
                strcpy(book[j].name, book[j + 1].name);
                strcpy(book[j + 1].name, a);
                int temp = book[j].price;
                book[j].price = book[j + 1].price;
                book[j + 1].price = temp;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        printf("%s\n", book[i].name);
    }
    return 0;
}
